﻿using SimpleServiceBus.Bus.MessageManagement.Callbacks;

namespace SimpleServiceBus.Bus.Pipeline.PipelineComponents
{
    public class LocalCallbackDispatcherComponent : PipelineComponentBase
    {
        public LocalCallbackDispatcherComponent():base("CallbackManager")
        {
        }

        protected override void ProcessMessage(MessageEnvelope messageEnvelope, IMessageContext context)
        {
            var svc = context.GetLocalService<ICorrelatedCallbackManager>();
            if (svc != null)
            {
                bool correlatedMessageHandled =
                    svc.Notify(messageEnvelope.CorrelationID, messageEnvelope.Body);

                if (correlatedMessageHandled)
                    context.AbortMessageProcessing = true;
            }
        }
    }
}